part of '../repository.dart';

const _kPurchasedSubscriptionTrialPeriodOfferTypeValue = 'trial_period';
const _kPurchasedSubscriptionPromotionalOfferTypeValue = 'promotional';
const _kPurchasedSubscriptionRegularOfferTypeValue = 'regular';

class _PurchasedSubscriptionTransactionOfferTypeDto extends Equatable {
  const _PurchasedSubscriptionTransactionOfferTypeDto._internal({
    required this.offerTypeString,
  });

  final String offerTypeString;

  @override
  List<Object?> get props {
    return [
      offerTypeString,
    ];
  }

  factory _PurchasedSubscriptionTransactionOfferTypeDto.fromString(String offerTypeString) {
    return _PurchasedSubscriptionTransactionOfferTypeDto._internal(
      offerTypeString: offerTypeString,
    );
  }

  factory _PurchasedSubscriptionTransactionOfferTypeDto.fromEntity(
      GooglePlayPurchasedSubscriptionTransactionOfferType offerType) {
    late final String offerTypeString;

    if (offerType == GooglePlayPurchasedSubscriptionTransactionOfferType.trialPeriod) {
      offerTypeString = _kPurchasedSubscriptionTrialPeriodOfferTypeValue;
    } else if (offerType == GooglePlayPurchasedSubscriptionTransactionOfferType.promotional) {
      offerTypeString = _kPurchasedSubscriptionPromotionalOfferTypeValue;
    } else if (offerType == GooglePlayPurchasedSubscriptionTransactionOfferType.regular) {
      offerTypeString = _kPurchasedSubscriptionRegularOfferTypeValue;
    }

    return _PurchasedSubscriptionTransactionOfferTypeDto._internal(
      offerTypeString: offerTypeString,
    );
  }

  @override
  String toString() {
    return offerTypeString;
  }

  GooglePlayPurchasedSubscriptionTransactionOfferType toEntity() {
    if (offerTypeString == _kPurchasedSubscriptionTrialPeriodOfferTypeValue) {
      return GooglePlayPurchasedSubscriptionTransactionOfferType.trialPeriod;
    } else if (offerTypeString == _kPurchasedSubscriptionPromotionalOfferTypeValue) {
      return GooglePlayPurchasedSubscriptionTransactionOfferType.promotional;
    } else if (offerTypeString == _kPurchasedSubscriptionRegularOfferTypeValue) {
      return GooglePlayPurchasedSubscriptionTransactionOfferType.regular;
    }

    throw UnimplementedError();
  }
}
